def import_author(zabbix, yml, host,result, id):
    new_hostid = result[id][0]  # ID of created host
    key2itemid = (
        {}
    )  # key: item key, value: itemid (will be used for dependent items and graph prototypes)

    if "applications" not in host:
        host["applications"] = {"application": []}
    if isinstance(host["applications"]["application"], dict):
        host["applications"]["application"] = [host["applications"]["application"]]
    apps = zabbix.application.get(
        hostids=new_hostid, output=["name", "applicationid"]
    )
    app2id = {}  # key: app name, value: app id
    for app in apps:
        app2id[app["name"]] = app["applicationid"]
    for app in host["applications"]["application"]:
        if app["name"] not in app2id:
            new_app = zabbix.application.create(
                name=app["name"], hostid=new_hostid
            )  # create missed apps
            app2id[app["name"]] = new_app["applicationids"][
                0
            ]  # save new app id for future use in items

    # if "items" in host or "discovery_rules" in host:
    #     # hack: use default interface for items
    #     iface = zabbix.hostinterface.get(
    #         output="interfaceid", hostids=new_hostid, filter={"main": 1}
    #     )
    #     new_ifaceid = iface[0]["interfaceid"]

    if "items" in host:
        if isinstance(host["items"]["item"], dict):
            host["items"]["item"] = [host["items"]["item"]]

        # create non-dependent items:
        for item in filter(lambda x: x["type"] != 18, host["items"]["item"]):
            if "applications" in item:
                if isinstance(item["applications"]["application"], dict):
                    item["applications"]["application"] = [
                        item["applications"]["application"]
                    ]
            else:
                item["applications"] = {"application": []}
            if "preprocessing" in item:
                if isinstance(item["preprocessing"]["step"], dict):
                    item["preprocessing"]["step"] = [item["preprocessing"]["step"]]
                for step in item["preprocessing"]["step"]:
                    if "params" not in step:
                        step["params"] = ""
                if api_version >= parse_version("4.0"):
                    for step in item["preprocessing"]["step"]:
                        if "error_handler" not in step:
                            step["error_handler"] = 0
                        if "error_handler_params" not in step:
                            step["error_handler_params"] = ""

            for app in item["applications"]["application"]:
                if app["name"] not in app2id:
                    logging.debug(app["name"])
                    new_app = zabbix.application.create(
                        name=app["name"], hostid=new_hostid
                    )  # create missed apps
                    app2id[app["name"]] = new_app["applicationids"][
                        0
                    ]

            zabbix.item.create(
                {
                    "delay": item["delay"],
                    "hostid": new_hostid,
                    # "interfaceid": new_ifaceid,
                    "key_": item["key"],
                    "name": item["name"],
                    "type": item["type"],
                    "value_type": item["value_type"],
                    "history": str(item["history"]) + "d",
                    "trends": str(item["trends"]) + "d",
                    "status": item["status"],
                    "units": item["units"] if "units" in item else "",
                    "authtype": item["authtype"],
                    "description": item["description"]
                    if "description" in item
                    else "",
                    "snmpv3_securitylevel": item["snmpv3_securitylevel"],
                    "snmpv3_authprotocol": item["snmpv3_authprotocol"],
                    "snmpv3_privprotocol": item["snmpv3_privprotocol"],
                    "snmp_community": item["snmp_community"]
                    if "snmp_community" in item
                    else "",
                    "snmp_oid": item["snmp_oid"] if "snmp_oid" in item else "",
                    "applications": [
                        app2id[x["name"]]
                        for x in item["applications"]["application"]
                    ],
                    "preprocessing": item["preprocessing"]["step"]
                    if "preprocessing" in item
                    else [],
                }
            )

        # fetch itemids for master items:
        for item in zabbix.item.get(
                output=["key_", "itemid"], hostids=new_hostid, webitems=True
        ):
            key2itemid[item["key_"]] = item["itemid"]

        # create dependent items:
        for item in filter(lambda x: x["type"] == 18, host["items"]["item"]):
            if "applications" in item:
                if isinstance(item["applications"]["application"], dict):
                    item["applications"]["application"] = [
                        item["applications"]["application"]
                    ]
            else:
                item["applications"] = {"application": []}
            if "preprocessing" in item:
                if isinstance(item["preprocessing"]["step"], dict):
                    item["preprocessing"]["step"] = [item["preprocessing"]["step"]]
                for step in item["preprocessing"]["step"]:
                    if "params" not in step:
                        step["params"] = ""
                if api_version >= parse_version("4.0"):
                    for step in item["preprocessing"]["step"]:
                        if "error_handler" not in step:
                            step["error_handler"] = 0
                        if "error_handler_params" not in step:
                            step["error_handler_params"] = ""

            zabbix.item.create(
                {
                    "delay": item["delay"],
                    "hostid": new_hostid,
                    # "interfaceid": new_ifaceid,
                    "key_": item["key"],
                    "name": item["name"],
                    "type": item["type"],
                    "value_type": item["value_type"],
                    "history": item["history"],
                    "trends": item["trends"],
                    "status": item["status"],
                    "master_itemid": key2itemid[item["master_item"]["key"]],
                    "units": item["units"] if "units" in item else "",
                    "authtype": item["authtype"],
                    "description": item["description"]
                    if "description" in item
                    else "",
                    "snmpv3_securitylevel": item["snmpv3_securitylevel"],
                    "snmpv3_authprotocol": item["snmpv3_authprotocol"],
                    "snmpv3_privprotocol": item["snmpv3_privprotocol"],
                    "snmp_community": item["snmp_community"]
                    if "snmp_community" in item
                    else "",
                    "snmp_oid": item["snmp_oid"] if "snmp_oid" in item else "",
                    "applications": [
                        app2id[x["name"]]
                        for x in item["applications"]["application"]
                    ],
                    "preprocessing": item["preprocessing"]["step"]
                    if "preprocessing" in item
                    else [],
                }
            )

    if "triggers" in yml:
        trigger2triggerid = get_trigger_cache(zabbix)  # get fresh trigger cache
        if isinstance(yml["triggers"]["trigger"], dict):
            yml["triggers"]["trigger"] = [yml["triggers"]["trigger"]]
        for trigger in yml["triggers"]["trigger"]:
            trigger["comments"] = (
                trigger["description"] if "description" in trigger else ""
            )
            trigger["description"] = trigger["name"]
            del trigger["name"]
            if "url" in trigger:
                if "://" not in trigger["url"]:
                    trigger["url"] = (
                            "https://" + trigger["url"]
                    )  # add missed scheme if needed
            if "dependencies" in trigger:  # resolve dependencies
                if isinstance(trigger["dependencies"]["dependency"], dict):
                    trigger["dependencies"]["dependency"] = [
                        trigger["dependencies"]["dependency"]
                    ]
                trigger["dependencies"] = [
                    {"triggerid": trigger2triggerid[(x["name"], host["name"])]}
                    for x in trigger["dependencies"]["dependency"]
                ]
            try:
                zabbix.trigger.create(trigger)
            except ZabbixAPIException as e:
                logging.error(e)

    if "discovery_rules" in host:
        if isinstance(host["discovery_rules"]["discovery_rule"], dict):
            host["discovery_rules"]["discovery_rule"] = [
                host["discovery_rules"]["discovery_rule"]
            ]
        for rule in host["discovery_rules"]["discovery_rule"]:
            rule["delay"] = str(rule["delay"])  # convert to string
            rule["proxy_hostid"] = new_hostid
            # rule["interfaceid"] = new_ifaceid
            rule["key_"] = rule["key"]
            del rule["key"]
            if "filter" in rule:
                if "conditions" not in rule["filter"]:
                    del rule["filter"]

            if "filter" in rule:
                if isinstance(rule["filter"]["conditions"]["condition"], dict):
                    rule["filter"]["conditions"]["condition"] = [
                        rule["filter"]["conditions"]["condition"]
                    ]
                rule["filter"]["conditions"] = rule["filter"]["conditions"][
                    "condition"
                ]

            new_rule = zabbix.discoveryrule.create(rule)
            new_ruleid = new_rule["itemids"][0]

            if "item_prototypes" in rule:
                if isinstance(rule["item_prototypes"]["item_prototype"], dict):
                    rule["item_prototypes"]["item_prototype"] = [
                        rule["item_prototypes"]["item_prototype"]
                    ]
                for item_prot in rule["item_prototypes"]["item_prototype"]:
                    item_prot["ruleid"] = new_ruleid
                    item_prot["key_"] = item_prot["key"]
                    del item_prot["key"]
                    item_prot["hostid"] = new_hostid
                    # item_prot["interfaceid"] = new_ifaceid

                    if "preprocessing" in item_prot:
                        if isinstance(item_prot["preprocessing"]["step"], dict):
                            item_prot["preprocessing"]["step"] = [
                                item_prot["preprocessing"]["step"]
                            ]
                        for step in item_prot["preprocessing"]["step"]:
                            if "params" not in step:
                                step["params"] = ""
                        if api_version >= parse_version("4.0"):
                            for step in item_prot["preprocessing"]["step"]:
                                if "error_handler" not in step:
                                    step["error_handler"] = 0
                                if "error_handler_params" not in step:
                                    step["error_handler_params"] = ""
                        item_prot["preprocessing"] = item_prot["preprocessing"][
                            "step"
                        ]

                    if "applications" in item_prot:
                        if isinstance(
                                item_prot["applications"]["application"], dict
                        ):
                            item_prot["applications"]["application"] = [
                                item_prot["applications"]["application"]
                            ]
                        item_prot["applications"] = [
                            app2id[app["name"]]
                            for app in item_prot["applications"]["application"]
                        ]  # resolve applications
                    zabbix.itemprototype.create(item_prot)

            if "trigger_prototypes" in rule:
                if isinstance(
                        rule["trigger_prototypes"]["trigger_prototype"], dict
                ):
                    rule["trigger_prototypes"]["trigger_prototype"] = [
                        rule["trigger_prototypes"]["trigger_prototype"]
                    ]
                for trigger_prot in rule["trigger_prototypes"]["trigger_prototype"]:
                    trigger_prot["comments"] = (
                        trigger_prot["description"]
                        if "description" in trigger_prot
                        else ""
                    )
                    trigger_prot["description"] = trigger_prot["name"]
                    del trigger_prot["name"]
                    if "url" in trigger_prot:
                        if "://" not in trigger_prot["url"]:
                            trigger_prot["url"] = (
                                    "https://" + trigger_prot["url"]
                            )  # add missed scheme if needed
                    if "dependencies" in trigger_prot:  # resolve dependencies
                        if isinstance(
                                trigger_prot["dependencies"]["dependency"], dict
                        ):
                            trigger_prot["dependencies"]["dependency"] = [
                                trigger_prot["dependencies"]["dependency"]
                            ]
                        trigger_prot["dependencies"] = [
                            {
                                "triggerid": trigger2triggerid[
                                    (x["name"], host["name"])
                                ]
                            }
                            for x in trigger_prot["dependencies"]["dependency"]
                        ]
                    zabbix.triggerprototype.create(trigger_prot)

            if "graph_prototypes" in rule:
                for item_prot in zabbix.itemprototype.get(
                        output=["key_", "itemid"], hostids=new_hostid
                ):
                    key2itemid[item_prot["key_"]] = item_prot["itemid"]

                if isinstance(rule["graph_prototypes"]["graph_prototype"], dict):
                    rule["graph_prototypes"]["graph_prototype"] = [
                        rule["graph_prototypes"]["graph_prototype"]
                    ]
                for graph_prot in rule["graph_prototypes"]["graph_prototype"]:
                    if isinstance(graph_prot["graph_items"]["graph_item"], dict):
                        graph_prot["graph_items"]["graph_item"] = [
                            graph_prot["graph_items"]["graph_item"]
                        ]
                    for gitem in graph_prot["graph_items"]["graph_item"]:
                        if "item" in gitem:
                            gitem["itemid"] = key2itemid[gitem["item"]["key"]]
                            del gitem["item"]
                            gitem["color"] = str(gitem["color"]).zfill(6)
                    graph_prot["gitems"] = graph_prot["graph_items"]["graph_item"]
                    del graph_prot["graph_items"]["graph_item"]
                    zabbix.graphprototype.create(graph_prot)

    if "graphs" in yml:
        if isinstance(yml["graphs"]["graph"], dict):
            yml["graphs"]["graph"] = [yml["graphs"]["graph"]]
        for graph in yml["graphs"]["graph"]:
            if isinstance(graph["graph_items"]["graph_item"], dict):
                graph["graph_items"]["graph_item"] = [
                    graph["graph_items"]["graph_item"]
                ]
            for gitem in graph["graph_items"]["graph_item"]:
                if "item" in gitem:
                    gitem["itemid"] = key2itemid[gitem["item"]["key"]]
                    del gitem["item"]
                    gitem["color"] = str(gitem["color"]).zfill(6)
            graph["gitems"] = graph["graph_items"]["graph_item"]
            del graph["graph_items"]["graph_item"]
            zabbix.graph.create(graph)